package com.website.web.back.controller.website;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.website.common.annotation.Log;
import com.website.common.enums.BusinessType;
import com.website.custom.domain.WConfig;
import com.website.custom.service.IWConfigService;
import com.website.common.core.controller.BaseController;
import com.website.common.core.domain.AjaxResult;
import com.website.common.utils.poi.ExcelUtil;
import com.website.common.core.page.TableDataInfo;

/**
 * 网站配置Controller
 * 
 * @author ruoyi
 * @date 2024-12-03
 */
@Controller
@RequestMapping("/back/custom/config")
public class WConfigController extends BaseController
{
    private String prefix = "back/website/config";

    @Autowired
    private IWConfigService wConfigService;

    @RequiresPermissions("system:config:view")
    @GetMapping()
    public String config()
    {
        return prefix + "/config";
    }

    /**
     * 查询网站配置列表
     */
    @RequiresPermissions("system:config:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WConfig wConfig)
    {
        startPage();
        List<WConfig> list = wConfigService.selectWConfigList(wConfig);
        return getDataTable(list);
    }

    /**
     * 导出网站配置列表
     */
    @RequiresPermissions("system:config:export")
    @Log(title = "网站配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WConfig wConfig)
    {
        List<WConfig> list = wConfigService.selectWConfigList(wConfig);
        ExcelUtil<WConfig> util = new ExcelUtil<WConfig>(WConfig.class);
        return util.exportExcel(list, "网站配置数据");
    }

    /**
     * 新增网站配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存网站配置
     */
    @RequiresPermissions("system:config:add")
    @Log(title = "网站配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WConfig wConfig)
    {
        return toAjax(wConfigService.insertWConfig(wConfig));
    }

    /**
     * 修改网站配置
     */
    @RequiresPermissions("system:config:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WConfig wConfig = wConfigService.selectWConfigById(id);
        mmap.put("wConfig", wConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存网站配置
     */
    @RequiresPermissions("system:config:edit")
    @Log(title = "网站配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WConfig wConfig)
    {
        return toAjax(wConfigService.updateWConfig(wConfig));
    }

    /**
     * 删除网站配置
     */
    @RequiresPermissions("system:config:remove")
    @Log(title = "网站配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wConfigService.deleteWConfigByIds(ids));
    }
}
